(function(factory) {
	if (typeof define === "function" && define.amd) {
		// AMD. Register as an anonymous module.
		define(['HteOS/page/Page'],factory);
	} else {
		// Browser globals
		factory();
	}
}(function() {
	
	/**
	 * 移动组件，页面管理器
	 *@class HteOS.page.PageManager
	 *@singleton
	 */
	HteOS.page.PageManager = {

		/**
		 *@property
		 *用于存放所有页面
		 */
		pages: {},

		/**
		 *初始化页面管理器
		 */
		init: function() {
		
			var manager = this;
		
			$(document).on('click','.hte-page-link',function(e){
				var id = $(this).parents(".hte-page").attr("id");
				//HteOS.page.PageManager.hide();
				HteOS.page.PageManager.get(id).hide();
			});
			
			HteOS.EventManager.on('hte.page.show',function(page){
				HteOS.page.PageManager.current = page;
			});
			
			HteOS.EventManager.on('hte.page.hide',function(){
				HteOS.page.PageManager.current = null;
			});
		},
		
		open : function(task){
			var page = this.create(task);
			page.show();
			return page;
		},
		
		create : function(task){
			if(this.current){
				task.prev = this.current.name;
			}
			return new HteOS.page.Page(task);
		},

		/**
		 *注册侧边栏
		 */
		register: function(page) {
			this.pages[page.id] = page;
		},

		unregister: function(page) {
			
			delete this.pages[page.id];
		},

		/**
		 *通过ID获取侧边栏
		 */
		get: function(id) {
			return this.pages[id];
		},
		
		hide : function(){
			if(this.current){
				this.current.hide();
			}
		}
	};
}));